package com.geeklan.base.network;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

public class UdpHelper {

    public static void sendWifiConfig(String deviceIp, int port, String ssid, String password) {
        new Thread(() -> {
            try {
                DatagramSocket socket = new DatagramSocket();
                InetAddress address = InetAddress.getByName(deviceIp);

                String message = "SSID:" + ssid + ";PASSWORD:" + password;
                byte[] data = message.getBytes();

                DatagramPacket packet = new DatagramPacket(data, data.length, address, port);
                socket.send(packet);

                socket.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }).start();
    }
}

